﻿local _, ns = ...

--边框变色
function ns.UpdateBorderColor(unitFrame,info)
	if unitFrame:IsForbidden() then return end
	if not unitFrame.unit then return end
	if not unitFrame.HealthBarsContainer then return end
	if not unitFrame.HealthBarsContainer.border then return end
	if not unitFrame.HealthBarsContainer.border.SetVertexColor then return end
	
	if PlateColorDB.mGlow and UnitIsUnit(unitFrame.unit, "mouseover") and not UnitIsUnit("player","mouseover") then
		unitFrame.HealthBarsContainer.border:SetVertexColor(0,1,1)
		
	elseif UnitIsUnit(unitFrame.unit, "target") then
		if UnitIsUnit("player","target") then
			unitFrame.HealthBarsContainer.border:SetVertexColor(0,0,0)
		elseif UnitIsPlayer(unitFrame.unit) then
			unitFrame.HealthBarsContainer.border:SetVertexColor(0.8,0.8,0.8)
		else
			unitFrame.HealthBarsContainer.border:SetVertexColor(1,1,1)
		end
	else
		unitFrame.HealthBarsContainer.border:SetVertexColor(0,0,0)
	end	
end

hooksecurefunc(GameTooltip,"SetWorldCursor", function(frame)
	if not PlateColorDB.mGlow then return end
	C_Timer.After(0,function()
		for i, namePlate in ipairs(C_NamePlate.GetNamePlates()) do
			ns.UpdateBorderColor(namePlate.UnitFrame)
		end
	end)
end)

hooksecurefunc("CompactUnitFrame_UpdateHealthBorder", function(frame)
	if frame:IsForbidden() then return end
	if not frame.unit then return end
	if frame.unit:lower():match("nameplate") then
		ns.UpdateBorderColor(frame)
	end
end)